#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <time.h>

void *readThread()
{
    char buffer[200];
    while (1)
    {
        fgets(buffer, 199, stdin);
        printf("[read data]: %s\n", buffer);
    }
}

void *writeThread()
{
    int count = 1;
    while (1)
    {
        printf("[write data]: %d\n", count);
        sleep(1);
    }
}

int main()
{
    int i = 1;
    pthread_t tid;
    int ret = pthread_create(&tid, NULL, readThread, NULL); // 不要传临时变量，这里是示范
    if (ret != 0)
    {
        perror("pthread_create");
        return -1;
    }
    ret = pthread_create(&tid, NULL, writeThread, NULL); // 不要传临时变量，这里是示范
    if (ret != 0)
    {
        perror("pthread_create");
        return -1;
    }
    while (1)
    {
        printf("i am main work thread\n");
        sleep(1000);
    }
    return 0;
}